'''
Created on Mar 16, 2012

@author: dolphinigle
'''

from Tkinter import *
import engine.elgamal

class GUI:
  def __init__(self, master):
    self.master = master
    frame = Frame(master)
    frame.grid(column=0, row=0, sticky=(N, W, E, S))
    frame.rowconfigure(0, weight=1)
    frame.columnconfigure(0, weight=1)
    frame.pack()

    self.done = PhotoImage(file="done.gif")
    self.photo = PhotoImage(file="logo.gif")
    self.think = PhotoImage(file="thinking.gif")

    self.logo = Label(frame, image=self.photo)
    self.logo.grid(row=1, column=2, sticky=(W))

    Label(frame, text='p (public):').grid(row=2, column=1, sticky=(W))
    Label(frame, text='g (public):').grid(row=3, column=1, sticky=(W))
    Label(frame, text='x (private):').grid(row=4, column=1, sticky=(W))
    Label(frame, text='y (public):').grid(row=5, column=1, sticky=(W))

    Button(frame, text='Generate!', command=self.generate_button_clicked).grid(
      row=6, column=1, sticky=(W))

    self.p = StringVar()
    self.g = StringVar()
    self.x = StringVar()
    self.y = StringVar()

    Entry(frame, width=80, textvariable=self.p).grid(
      row=2, column=2, sticky=(W))
    Entry(frame, width=80, textvariable=self.g).grid(
      row=3, column=2, sticky=(W))
    Entry(frame, width=80, textvariable=self.x).grid(
      row=4, column=2, sticky=(W))
    Entry(frame, width=80, textvariable=self.y).grid(
      row=5, column=2, sticky=(W))

  def generate_button_clicked(self):
    self.logo.configure(image = self.think)
    self.logo.update()
    
    (pp, gg, xx, yy) = engine.elgamal.GenKey()
    self.p.set(pp)
    self.g.set(gg)
    self.x.set(xx)
    self.y.set(yy)
    self.logo.configure(image = self.done)

if __name__ == '__main__':
  root = Tk()
  mg = GUI(root)
  root.mainloop();
